import { getStorage, setStorage, removeStorage } from '/src/_util/storage.js'

export default {
	namespaced: true,
    state: {
		// 侧边栏菜单
        asideMenus: getStorage('VEA_ASIDEMENUS') || [],
		
		// 拥有的权限
		permissions: getStorage('VEA_PERMISSIONS') || [],
		
		// 拥有的路由列表
		haveRoutes: getStorage('VEA_HAVEROUTES') || [],
		
		// 是否收缩菜单
		collapse: getStorage('VEA_COLLAPSE') || 0,
		
		// 是否显示菜单
		showMenu: getStorage('VEA_SHOWMENU') || 0,
		
		// 激活的子菜单
		activeMenus: getStorage('VEA_ACTIVEMENUS') || [],
		
		// 激活的菜单项
		activeMenuItem: getStorage('VEA_ACTIVEMENUITEM') || '',
		
		// 打开的页面
		pageTags: getStorage('VEA_PAGETAGS') || [],
		
    },
    mutations: {
		// 设置菜单数据
        setAsideMenus (state, menus) {
			state.asideMenus = menus
			setStorage('VEA_ASIDEMENUS', menus)
		},
		
		// 设置权限数据
		setPermissions (state, permissions) {
			state.permissions = permissions
			setStorage('VEA_PERMISSIONS', permissions)
		},
		
		// 设置用户拥有的路由
		setHaveRoutes (state, routes) {
			state.haveRoutes = routes
			setStorage('VEA_HAVEROUTES', routes)
		},
		
		// 设置菜单收缩状态
		setCollapse (state, collapse) {
			state.collapse = collapse
			setStorage('VEA_COLLAPSE', collapse)
		},
		
		// 设置菜单显示状态
		setShowMenu (state, show) {
			state.showMenu = show
			setStorage('VEA_SHOWMENU', show)
		},
		
		// 设置激活的子菜单
		setActiveMenus (state, activeMenus) {
			state.activeMenus = activeMenus
			setStorage('VEA_ACTIVEMENUS', activeMenus)
		},
		
		// 设置激活的菜单项
		setActiveMenuItem (state, activeMenuItem) {
			state.activeMenuItem = activeMenuItem
			setStorage('VEA_ACTIVEMENUITEM', activeMenuItem)
		},
		
		// 设置打开的页面标签
		setPageTags (state, pageTags) {
			state.pageTags = pageTags
			setStorage('VEA_PAGETAGS', pageTags)
		},
		
		// 重置 store 状态数据
		resetAppStore (state) {
			state.asideMenus = []
			state.haveRoutes = []
			state.collapse = 0
			state.showMenu = 0
			state.activeMenus = []
			state.activeMenuItem = ''
			state.pageTags = []
			
			removeStorage('VEA_ASIDEMENUS')
			removeStorage('VEA_PERMISSIONS')
			removeStorage('VEA_HAVEROUTES')
			removeStorage('VEA_COLLAPSE')
			removeStorage('VEA_SHOWMENU')
			removeStorage('VEA_ACTIVEMENUS')
			removeStorage('VEA_ACTIVEMENUITEM')
			removeStorage('VEA_PAGETAGS')
		}
    }
}
